package com.qinggeng.framework.web.domain;

import java.util.HashMap;
import com.qinggeng.common.constant.HttpStatus;
import com.qinggeng.common.enums.ShowTypeEnum;
import com.qinggeng.common.utils.StringUtils;
import com.sun.webkit.ContextMenu;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.aspectj.weaver.loadtime.Aj;

/**
 * 操作消息提醒
 * 
 * @author qinggeng
 */
@Data
public class AjaxResult extends HashMap<String, Object>
{
    private static final long serialVersionUID = 1L;

    /** 状态码 */
    @ApiModelProperty(value = "状态码")
    private int code;

    private int type;

    private String msg;

    private String content;

    public static final String CODE_TAG = "code";

    /** 返回内容 */
    public static final String MSG_TAG = "msg";

    /** 展示类型 */
    public static final String SHOW_TYPE="type";

    /** 展示内容 */
    public static final String SHOW_CONTENT="content";

    /** 数据对象 */
    public static final String DATA_TAG = "data";

    /**
     * 初始化一个新创建的 AjaxResult 对象，使其表示一个空消息。
     */
    public AjaxResult() {
    }

    public AjaxResult(int code, String msg,int type,Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        if(StringUtils.isNotNull(type)){
            super.put(SHOW_TYPE,type);
            if(type==ShowTypeEnum.用户.getValue()){
                super.put(SHOW_CONTENT,msg);
            }
        }
        if (StringUtils.isNotNull(data)){
            super.put(DATA_TAG, data);
        }
    }

    public AjaxResult(int code, String msg,int type,String content,Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        super.put(SHOW_TYPE,type);
        if(type==ShowTypeEnum.用户.getValue()){
            super.put(SHOW_CONTENT,content);
        }
        if (StringUtils.isNotNull(data)){
            super.put(DATA_TAG, data);
        }
    }

    /**
     * 返回成功消息
     * 
     * @return 成功消息
     */
    public static AjaxResult success()    {
        return new AjaxResult(HttpStatus.SUCCESS,"操作成功！",ShowTypeEnum.后台.getValue(),null);
    }

    public static AjaxResult success(Object data)  {
        return new AjaxResult(HttpStatus.SUCCESS,"操作成功！",ShowTypeEnum.后台.getValue(),data);
    }
    public static AjaxResult success(String msg,int type){
        return new AjaxResult(HttpStatus.SUCCESS,msg,type,null);
    }
    public static AjaxResult success(String msg,Object data){
        return new AjaxResult(HttpStatus.SUCCESS,msg,ShowTypeEnum.后台.getValue(),data);
    }

    public static AjaxResult success(String msg, int type,Object data){
        return new AjaxResult(HttpStatus.SUCCESS,msg, type, data);
    }

    public static AjaxResult error(String msg,int type) {
        return new AjaxResult(HttpStatus.ERROR,msg,type,null);
    }

    public static AjaxResult error(int code,String msg){
        return new AjaxResult(code, msg, ShowTypeEnum.用户.getValue(), msg,null);
    }
    public static AjaxResult error(int code,String msg,int type){
        return new AjaxResult(code,msg,type,msg,null);
    }

    public static AjaxResult error(String msg ,Object data) {
        return new AjaxResult(HttpStatus.ERROR, msg, ShowTypeEnum.后台.getValue(),data);
    }

    public static AjaxResult error(String msg,int type, Object data) {
        return new AjaxResult(HttpStatus.ERROR, msg, type,data);
    }
    public static AjaxResult error(String msg,int type, String content,Object data) {
        return new AjaxResult(HttpStatus.ERROR, msg, type,content,data);
    }
    public static AjaxResult error(String content) {
        return new AjaxResult(HttpStatus.ERROR, content, ShowTypeEnum.用户.getValue(), content,null);
    }
}
